package com.woody.aggregate.application.service.shop.es.strategy;

import com.woody.aggregate.application.service.shop.es.strategy.impl.AbstractBaseShopConverterStrategy;
import com.woody.aggregate.common.consts.es.ShopChangeTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

/**
 * 门店信息转换策略工厂
 *
 * @author wénkǎi.zhāng
 */
@Component
public class ShopInfoConverterStrategyFactory {

    private static final Map<ShopChangeTypeEnum, ShopInfoConverterStrategy> STRATEGIES = new EnumMap<>(ShopChangeTypeEnum.class);


    public ShopInfoConverterStrategyFactory(List<AbstractBaseShopConverterStrategy> strategies) {
        strategies.forEach(strategy -> STRATEGIES.put(strategy.getStrategyType(), strategy));
    }


    /**
     * 获取对应的转换策略
     *
     * @param type 门店变更类型
     * @return 转换策略
     */
    public static ShopInfoConverterStrategy getStrategy(ShopChangeTypeEnum type) {
        ShopInfoConverterStrategy strategy = STRATEGIES.get(type);
        if (strategy == null) {
            throw new IllegalArgumentException("门店变更类型不支持: " + type);
        }
        return strategy;
    }
}
